/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package beans.util;

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 *
 * @author marcy
 */
public class AlreadyVisitedListBean {

    private List<Object[]> lista;

    public List<Object[]> getLista() {
        if (lista == null) {
            EntityManagerFactory emf = Persistence.createEntityManagerFactory("PortaleVisitePU");
            EntityManager em = emf.createEntityManager();
            lista = (List<Object[]>) em.createNativeQuery("Select P.id, P.nome, P.cognome, P.data_nascita, sum( E.effettuata ) "
                    + "FROM Patient P, Examination E "
                    + "WHERE P.id = E.id_pat "
                    + "AND E.scadenza < now() "
                    + "AND E.effettuata = 1 "
                    + "Group By P.id ").getResultList();
        }
        return lista;
    }

    public void setLista(List<Object[]> lista) {
        this.lista = lista;
    }
    
}
